package main

import (
	"fmt"
	"sync"
	"time"
)

/*
线程安全的map
Delete  删除
Load	读取
Range	遍历
Store	添加
*/
func main() {
	var maph sync.Map
	for i := 0; i < 3; i++ {
		go func(i int) {
			maph.Store(i, i)
		}(i)
	}
	for i := 0; i < 10; i++ {
		maph.Range(func(key, value interface{}) bool {
			fmt.Printf("%d: %d\t", key, value)
			return true
		})
		fmt.Println()
		time.Sleep(time.Second)
	}

	v ,_ := maph.Load(2)
	fmt.Println(v)
}
